'use strict';

const Controller = require('egg').Controller;

class zfmuserController extends Controller {
  async listAll() {
        const result = await this.service.zfmuserSer.listAll();
        this.ctx.body = {
            code: 200,
            message: '查询用户所有信息成功',
            result
        }
    }

    async listAlluser() {
        let result = await this.service.zfmuserSer.listAlluser();
        this.ctx.body = {
            code: 200,
            message: '查询用户所有信息成功',
            result
        }
    }

    async listuser() {
        let paramsObject = this.ctx.request.body;
        let result = await this.service.zfmuserSer.listuser(paramsObject);
        this.ctx.body = {
            code: 200,
            message: '按条件查询用户成功',
            result
        }
    }
    async addNewuser() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.addNewuser(user);
        if (result !== 0) {
            this.ctx.body = {
                statuscode: 200,
                title: '新增成功',
                affectrow: result.affectedRows
            }
        }
        else {
            this.ctx.body = {
                statuscode: 500,
                message: '用户已存在',
                affectrow: 0
            }
        }
    }

    async edituser() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.edituser(user);
        this.ctx.body = {
            statuscode: 200,
            title: '查询成功！',
            result
        }
    }

    async updateTuser() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.updateTuser(user);
        this.ctx.body = {
            statuscode: 200,
            title: '修改成功！',
            affectrow: result.affectedRows
        }
    }

    async deleteTuser() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.deleteTuser(user);
        this.ctx.body = {
            statuscode: 200,
            title: '删除改成功！',
            affectrow: result.affectedRows
        }
    }

    async updatestatus() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.updatestates(user);
        this.ctx.body = {
            statuscode: 200,
            title: '修改成功！',
            affectrow: result.affectedRows
        }
    }

    async userrole() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.userrole(user);
        this.ctx.body = {
            statuscode: 200,
            title: '查询成功！',
            result
        }
    }

    async notuserrole() {
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.notuserrole(user);
        this.ctx.body = {
            statuscode: 200,
            title: '查询成功！',
            result
        }
    }

    async adduserrole(){
        let user = this.ctx.request.body;
        let result = await this.service.zfmuserSer.adduserrole(user);
        this.ctx.body = {
            statuscode: 200,
            title: '插入成功！',
            //affectrow: result.affectedRows
            result
        }
    }
}

module.exports = zfmuserController;
